﻿#include <iostream>
#include <omp.h>
#include <thread>

void star(double* a, double* b, double* c, int n, int* ioff) {
    #pragma omp simd
    for (int i = 0; i < n; i++) {
        a[i] *= b[i] * c[i + *ioff];
    }
}

int main() {
    const int N = 100000;
    double* a = new double[N];      // 用堆存储
    double* b = new double[N];
    double* c = new double[N + 2];  // 避免越界
    int offset = 2;

    // 初始化数组
    for (int i = 0; i < N; i++) {
        a[i] = 1.0;
        b[i] = 2.0;
        c[i] = 3.0;
    }

    std::cout << "OpenMP max threads: " << omp_get_max_threads() << std::endl;

    star(a, b, c, N, &offset);

    // 打印部分结果
    for (int i = 0; i < 10; i++) {
        std::cout << "a[" << i << "] = " << a[i] << std::endl;
    }

    // 释放内存
    delete[] a;
    delete[] b;
    delete[] c;

    // 避免窗口关闭
    std::cout << "Press Enter to exit...";
    std::cin.get();

    return 0;
}
